package composite.example;

import composite.source.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Chen Guang
 * @date 2019/4/18 0018 上午 11:31
 */
public class ConcreteCompany implements Company{

    private String name;
    private List<Company> children = new ArrayList<>();

    public ConcreteCompany(String name) {
        this.name = name;
    }

    @Override
    public void add(Company company) {
        children.add(company);
    }

    @Override
    public void remove(Company company) {
        children.remove(company);
    }

    @Override
    public void display(int depth) {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < depth; i++) {
            str.append("-");
        }
        str.append(this.name);
        System.out.println(str);

        for(Company company : children){
            company.display(depth + 2);
        }
    }

    @Override
    public void lineOfDuty() {
        for(Company company : children){
            company.lineOfDuty();
        }
    }
}
